from rest_framework.views import APIView
from rest_framework.response import Response
from django.contrib.auth import logout

class User_Logout(APIView):
    def post(self, request, *args, **kwargs):
        request.try_except(logout, request)
        return Response({"detail": "用户退出成功"})


    # def post(self, request, *args, **kwargs):
    #     if not request.user.is_authenticated:
    #         return Response({"detail": "用户未登录，无需退出"})
    #     # logout(request)
    #     return Response({"detail": "用户退出成功"})